package com.core;

import java.net.MalformedURLException;
import java.net.URL;

import com.douban.constants.DoubanConstant;

import sun.net.www.http.HttpClient;

/**
 * A class to construct douban urls singleton
 * @author SELuoc
 *
 */
public class DoubanURL  {

	private static DoubanURL dburl = null;	
	
	private  DoubanURL() {
		
	}
	
	public static DoubanURL getInstance(){
		if(dburl==null){
			dburl = new DoubanURL();
		}
		return dburl;
	}
	
	/**
	 * 
	 * @param username the douban user name
	 */
	public URL getURL(String username, String mediaType, String userAction, int start){
		
		URL url = null;
		
		String urlString = "http://" + mediaType +  "." + DoubanConstant.DOUBAN.getValue() + "/" + DoubanConstant.PEOPLE.getValue()
			+ "/" + username +"/" + 
			userAction +"?start="+ start +"&sort=time&mode=list&";

//		http://movie.douban.com/people/andmay/
//		wish?
//		start=0&
//		sort=time&
//		mode=list&
		
		try {
			url = new URL(urlString);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			System.out.println("Wrong url format with url:" + urlString);
		}
		
		return url;

	}
}
